package com.perritosca.frankriptalo;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;

import org.apache.commons.codec.binary.Base64;


public class Main extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
public void clickEncriptar(View radio1){
	 EditText text1 = (EditText)findViewById(R.id.text1);
	 String texto=text1.getText().toString();
	 String textoencrip=encriptar(texto);
	 EditText text2 = (EditText)findViewById(R.id.text2);
	 text2.setText(textoencrip);
	}
	
public void clickDesencriptar(View radio2){
	EditText text1 = (EditText)findViewById(R.id.text1);
	 String texto=text1.getText().toString();
	 String textoencrip=desencriptar(texto);
	 EditText text2 = (EditText)findViewById(R.id.text2);
	 text2.setText(textoencrip);
	}
	
	public String encriptar(String cadena){
		
        //encoding  byte array into base 64
        byte[] encoded = Base64.encodeBase64(cadena.getBytes());     
        return new String(encoded);
		
	}
	
public String desencriptar(String cadena){
	
		byte[] decoded = Base64.decodeBase64(cadena.getBytes());    
        return new String(decoded);
	}
public void share(View radio) {
	 final Intent intent = new Intent(Intent.ACTION_SEND);
	 EditText text1 = (EditText)findViewById(R.id.text2);
	 String texto=text1.getText().toString();
	 intent.setType("text/plain");
	 intent.putExtra(Intent.EXTRA_TEXT, texto);

	 startActivity(Intent.createChooser(intent, "compartir"));
	 
	}
public void limpiar(View radio) {
	 EditText text1 = (EditText)findViewById(R.id.text1);
	 text1.setText("");
	 EditText text2 = (EditText)findViewById(R.id.text2);
	 text2.setText("");
	}

   
}
